home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Topik / Topik - Disk 04 - Disk and Technical Stuff (19xx)(Topik Public Domain)(PD)[WB].zip / Topik - Disk 04 - Disk and Technical Stuff (19xx)(Topik Public Domain)(PD)[WB].adf / DriveTests / DiskVerify.c < prev    next >
C/C++ Source or Header  |  1989-06-22  |  5KB  |  193 lines

  1. /*    DiskVerify.c - Track read of disk for verification */
  2.  
  3. /*
  4.  *    Written by Michael L. Hitch
  5.  *    Bozeman, MT
  6. */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/nodes.h>
  10. #include <exec/lists.h>
  11. #include <exec/memory.h>
  12. #include <exec/interrupts.h>
  13. #include <exec/ports.h>
  14. #include <exec/libraries.h>
  15. #include <exec/io.h>
  16. #include <exec/tasks.h>
  17. #include <exec/execbase.h>
  18. #include <exec/devices.h>
  19. #include <devices/trackdisk.h>
  20. #include <libraries/dos.h>
  21. #include <libraries/dosextens.h>
  22. #include <libraries/filehandler.h>
  23.  
  24. #define    TD_READ    CMD_READ
  25.  
  26. extern struct DosLibrary *DOSBase;        /* DOS Library base pointer */
  27.  
  28. SHORT error;
  29. struct MsgPort *read_port;
  30. struct IOExtTD *read_req;
  31.  
  32. char *device_name;
  33.  
  34. unsigned long unit;                    /* unit number */
  35. unsigned long numsects;                /* number of sectors/track */
  36. unsigned long numheads;                /* number of heads/cylinder */
  37. unsigned long locyl;                /* low cylinder number */
  38. unsigned long hicyl;                /* high cylinder number */
  39.  
  40. BYTE *diskbuffer;
  41.  
  42. extern struct MsgPort *CreatePort();
  43. extern struct IORequest *CreateExtIO();
  44.  
  45. main(argc, argv)
  46. int argc;
  47. char *argv[];
  48. {
  49.     SHORT cylinder, head;
  50.     char buf[128];
  51.     
  52.     read_port = CreatePort(0, 0);
  53.     if (read_port == NULL)
  54.         quit(100);
  55.     read_req = (struct IOExtTD *) CreateExtIO(read_port,
  56.         sizeof(struct IOExtTD));
  57.     if (read_req == NULL)
  58.         quit(200);
  59.     strcpy(buf, "df1");
  60.     if (argc > 1)
  61.         strcpy(buf, argv[1]);
  62.     if (buf[3] == ':')
  63.         buf[3] = 0;
  64.     init_device (buf);
  65.     error = OpenDevice (device_name, unit, read_req, 0);
  66.     if (error) {
  67.         printf("OpenDevice return was: %lx\n", error);
  68.         quit(1);
  69.     }
  70.     if (argc > 2)
  71.         printf ("LowCyl=%ld, HighCyl=%ld, NumHeads=%ld, %NumSects=%ld\n",
  72.             locyl, hicyl, numheads, numsects);
  73.     if ((diskbuffer = (BYTE *) AllocMem (TD_SECTOR * numsects * numheads
  74.         , MEMF_CHIP)) == NULL) {
  75.         printf("Unable to allocate cylinder buffer\n");
  76.         CloseDevice(read_req);
  77.         quit(1);
  78.     }
  79.     printf("Insert disk to be verified in drive %s: and enter return: ",
  80.         buf);
  81.     if (Read (Input(), buf, 128) <= 0)
  82.         printf("\n");
  83.     printf("\233\060 p");        /* turn cursor off */
  84.     for (cylinder = locyl; cylinder <= hicyl; ++cylinder) {
  85.         printf("\rCyl=%ld", cylinder);
  86.         ReadCyl(cylinder);
  87.         if (read_req->iotd_Req.io_Error != 0) {
  88.             /* compute head from io_Actual */
  89.             head = read_req->iotd_Req.io_Actual;
  90.             head = head / (TD_SECTOR * numsects);
  91.             head = head % numheads;
  92.             printf(
  93.               "\2337m\nError on Cyl=%ld, Hd=%ld, Error=%ld\233m\n",
  94.                 cylinder, head,
  95.                 read_req->iotd_Req.io_Error);
  96.         }
  97.         if (read_req->iotd_Req.io_Error == TDERR_DiskChanged)
  98.             break;
  99.         Chk_Abort();
  100.     }
  101.     printf("\nVerify completed\n");
  102.     MotorOff();
  103.     CloseDevice(read_req);
  104.     quit(0);
  105. }
  106.  
  107. ReadCyl(cyl)
  108. SHORT cyl;
  109. {
  110.     LONG offset;
  111.  
  112.     read_req->iotd_Req.io_Length = TD_SECTOR * numsects * numheads;
  113.     read_req->iotd_Req.io_Data = (APTR) diskbuffer;
  114.     read_req->iotd_Req.io_Command = CMD_READ;
  115.     offset = cyl * numheads * numsects * TD_SECTOR;
  116.     read_req->iotd_Req.io_Offset = offset;
  117.     DoIO(read_req);
  118.     return(0);
  119. }
  120.  
  121. MotorOff()
  122. {
  123.     read_req->iotd_Req.io_Length = 0;
  124.     read_req->iotd_Req.io_Command = TD_MOTOR;
  125.     DoIO(read_req);
  126.     return(0);
  127. }
  128.  
  129. quit(return_code)
  130. {
  131.     if (diskbuffer)
  132.         FreeMem (diskbuffer, TD_SECTOR * numsects * numheads);
  133.     if (read_req)
  134.         DeleteExtIO(read_req);
  135.     if (read_port)
  136.         DeletePort(read_port);
  137.     printf("\233 p");        /* turn cursor back on */
  138.     exit(return_code);
  139. }
  140.  
  141. Chk_Abort()
  142. {
  143.     if (SetSignal(0, SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D) &
  144.         (SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D)) {
  145.         MotorOff ();
  146.         CloseDevice (read_req);
  147.         printf("\n");
  148.         quit (0);
  149.     }
  150. }
  151.  
  152. init_device (name)
  153. register char *name;
  154. {
  155.     struct RootNode *root_node;
  156.     struct DosInfo *info_node;
  157.     register struct DeviceNode *device_node;
  158.     struct FileSysStartupMsg *startup_msg;
  159.     unsigned long *envptr;
  160.     root_node = (struct RootNode *) DOSBase->dl_Root;
  161.     info_node = (struct DosInfo *) BADDR (root_node->rn_Info);
  162.     device_node = (struct DeviceNode *) BADDR (info_node->di_DevInfo);
  163.     while (device_node) {
  164.         if (device_node->dn_Type == DLT_DEVICE ) {
  165.             if (match (name, BADDR (device_node->dn_Name) + 1) == 0)
  166.                 break;
  167.         }
  168.         device_node = (struct DeviceNode *) BADDR (device_node->dn_Next);
  169.     }
  170.     if (device_node == 0) {
  171.         printf ("Device %s: not found\n", name);
  172.         quit (1);
  173.     }
  174.     startup_msg = (struct FileSysStartupMsg *) BADDR (device_node->dn_Startup);
  175.     unit = startup_msg->fssm_Unit;        /* unit number */
  176.     device_name = (char *) BADDR (startup_msg->fssm_Device) + 1;
  177.     envptr = (long *) BADDR (startup_msg->fssm_Environ);
  178.     locyl = envptr[DE_LOWCYL];
  179.     hicyl = envptr[DE_UPPERCYL];
  180.     numheads = envptr[DE_NUMHEADS];
  181.     numsects = envptr[DE_BLKSPERTRACK];
  182. }
  183.  
  184. match (s1, s2)
  185. register char *s1, *s2;
  186. {
  187.     register char c;
  188.     while ((c = toupper (*s1++)) == toupper (*s2++))
  189.         if (c == 0)
  190.             return (0);
  191.     return (1);
  192. }
  193.